#ifndef _FLASH_H
#define _FLASH_H

#include "sn_config.h"




struct flash_dev_t
{
   // uint8_t magic;//魔数
    uint16_t size;//page_num*page_size
    uint8_t page_num;//页数
    uint16_t page_size;//一页多少个字节
  //  uint32_t *start_addr; //flash 起始地址
    uint8_t *cache;
    
    int (*write_byte   )(struct flash_dev_t *dev,uint16_t num,uint8_t  val);
    int (*read_byte    )(struct flash_dev_t *dev,uint16_t num,uint8_t* val);
    /**
     * @brief 写入flash buf 大小为页大小
     * 
     * @param dev       flash 句柄
     * @param page      页编号 从0 开始
     * @param pwbuf     写入首地址
     * @param size      写入长度
     * @return int 
     */
    int (*write_page   )(struct flash_dev_t *dev,uint8_t page,uint8_t *pwbuf,uint16_t size);
    int (*read_page    )(struct flash_dev_t *dev,uint8_t page,uint8_t *prbuf,uint16_t size);
    int (*read_array   )(struct flash_dev_t *dev,uint16_t start_num,uint8_t* prbuf,uint8_t len);
  /**
   * @brief 向flash 写入指定长度的数组
   * 
   * @param dev 
   * @param start_num   起始位置
   * @param pwbuf       数组首地址
   * @param len         数组长度
   * @return int 
   */
    int (*write_array  )(struct flash_dev_t *dev,uint16_t start_num,uint8_t* pwbuf,uint8_t len);
    int (*read_allpage )(struct flash_dev_t *dev);
    int (*write_allpage)(struct flash_dev_t *dev);
    int (*refresh      )(struct flash_dev_t *dev);
    int (*check_magic  )(struct flash_dev_t *dev);
};
int flash_init(struct flash_dev_t **dev);

#endif // !_FLASH_H

